import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bmfmap_example/http/http.dart';
import 'package:flutter_bmfmap_example/pages/homepage/pages/Equipment_message/tool/tool.dart';

import 'Equipment_all_value/Equipment_all_value.dart';

class EquipmentCard extends StatefulWidget {
  EquipmentCard({Key key, this.typeId, this.deviceId, this.imgUrl, this.list})
      : super(key: key);
  String imgUrl;
  int typeId;
  int deviceId;
  List list = [];
  // void read() {
  //   this.state = 1;

  //   createState();
  // }

  @override
  _equipmentCardState createState() => _equipmentCardState();
}

class _equipmentCardState extends State<EquipmentCard> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    // 页面加载时调用 用来开始时访问数据库
  }

  initstate() {
    print('*************************************');
    print(widget.list);
  }

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        widget.list[0]['state'] = 1;
        isread(widget.typeId,widget.deviceId);
        Navigator.of(context).push(MaterialPageRoute(
          builder: (context) {
            return Equipment_all_value(
              // name: widget.typeId,
              typeId: widget.typeId,
              deviceId: widget.deviceId,
              list: widget.list,
            ); //返回的是需要跳转单页面
          },
        ));
        setState(() {});
      },
      child: Container(
        padding: EdgeInsets.all(8),
        margin: EdgeInsets.all(8),
        height: 64,
        decoration: new BoxDecoration(
            color: Colors.white,
            borderRadius: new BorderRadius.circular((10.0)),
            boxShadow: [
              BoxShadow(
                  color: Colors.black12,
                  offset: Offset(0.0, 0.0), //阴影xy轴偏移量
                  blurRadius: 5.0, //阴影模糊程度
                  spreadRadius: 0.1 //阴影扩散程度
                  )
            ]),
        child: Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
          Container(
            child: Image.asset(
              widget.imgUrl,
              // fit: BoxFit.none,
            ),
            height: 48,
            width: 48,
          ),
          Padding(
            padding: const EdgeInsets.only(left: 8.0),
            child:
                Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
              Text(
                Tool.getName(widget.typeId, widget.deviceId),
                style: TextStyle(
                  color: Colors.black87,
                  fontSize: 15,
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(left: 5.0),
                child: Container(
                  width: 150,
                  child: Expanded(
                    child: Text(
                      widget.list[0]['content'],
                      style: TextStyle(
                          color: Colors.black38,
                          decoration: TextDecoration.none),
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                    ),
                  ),
                ),
              ),
            ]),
          ),
          Spacer(),
          Container(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                Container(
                  width: 70,
                  child: Text(
                    Tool.getTime(widget.list[0]['created']),
                    // widget.time,
                    style: TextStyle(color: Colors.black38, fontSize: 12),
                  ),
                ),
                Container(
                  width: 8,
                  height: 8,
                  margin: EdgeInsets.only(left: 40),
                  decoration: new BoxDecoration(
                    color: widget.list[0]['state'] == 0
                        ? Colors.red
                        : Colors.white,
                    borderRadius: new BorderRadius.circular((4.0)),
                  ),
                ),
              ],
            ),
          ),
        ]),
      ),
    );
  }
  isread(int typeId,int deviceId) async {
    var response =
        await Http.get('/notice/updateState?typeId=$typeId&deviceId=$deviceId');
  }
}
